﻿<Page
    x:Class="vsarFlightPlan.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:vsarFlightPlan"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converters="using:vsarFlightPlan.Converters"
    x:Name="page"
    mc:Ignorable="d">
    <Page.Resources>
        <converters:DateTimeToDateTimeOffsetConverter x:Key="DateTimeToDateTimeOffset" />
        <converters:BooltoVisibilityConverter x:Key="InvertedBooltoVisibility" InvertResult="True" />
        <converters:BooltoVisibilityConverter x:Key="BooltoVisibility" />
        <converters:EmptyStringToVisibilityConverter x:Key="ShowStringsWithValues" />
        <converters:EmptyStringToVisibilityConverter x:Key="ShowEmptyStrings" InvertResult="True" />
        <converters:StatusToBrush x:Key="StatusToBrushConverter" />
        <converters:StringFormatConverter x:Key="StringFormatConverter" />
        <converters:StatusToIcon x:Key="StatusToIcon" />
        <converters:DateTimeOffsetPrettifier x:Key="DateTimeOffsetPrettifier" />
        <converters:DateTimePrettifier x:Key="DateTimePrettifier" />
        <converters:BooleanToStringConverter x:Key="BooleanToStringConverter" FalseValue="Showing ALL" TrueValue="Filtered" />

        <DataTemplate x:Key="DetailedItemDataTemplate">
            <Button Margin="0" Padding="0" Style="{StaticResource HiddenButtonStyle}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" BorderThickness="0">
                <Grid Margin="0" Background="{Binding Status, Converter={StaticResource StatusToBrushConverter}}" HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="4*" />
                        <ColumnDefinition Width="32" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Margin="5" TextTrimming="CharacterEllipsis" Grid.Column="0" VerticalAlignment="Center" FontWeight="Light" HorizontalAlignment="Left" Text="{Binding Title, FallbackValue='Mega Man'}" FontSize="18" />
                    <ContentControl Width="32" Height="32" Grid.Column="1" Style="{Binding Status, Converter={StaticResource StatusToIcon}}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </Button>
        </DataTemplate>
    </Page.Resources>
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.SecondaryCommands>
                <AppBarButton Label="Settings" Click="SettingsAppBarButtonClick" />
                <AppBarButton Label="Provide Feedback" Click="ProvideFeedbackAppBarButtonClick" />
                <AppBarButton Label="Privacy Policy" Click="PrivacyPolicyAppBarButtonClick" />
            </CommandBar.SecondaryCommands>
            <AppBarButton Label="Refresh" Icon="Refresh" Command="{Binding Refresh}" />
            <AppBarToggleButton Label="{Binding ShowAllItems, Converter={StaticResource BooleanToStringConverter}, FallbackValue=Show All}" Icon="Preview" Command="{Binding ToggleHiddenItems}" />
            <AppBarButton Label="Save Image" Icon="Save" Click="AppBarSaveButton_Click" />
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background="{StaticResource Background}">
        <Grid Margin="12">
            <Grid.RowDefinitions>
                <RowDefinition Height="45" />
                <RowDefinition Height="40" />
                <RowDefinition Height="10" />
                <RowDefinition Height="30" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Grid.Row="0">
                <ContentControl Grid.Column="0" Style="{StaticResource IconPlane}" Width="32" Height="32" Margin="0,0,10,0" />
                <TextBlock TextWrapping="NoWrap" VerticalAlignment="Center" Grid.Column="1" Style="{StaticResource TitleTextBlockStyle}" Foreground="{StaticResource PrimaryColourBrush}">
                    FLIGHT PLAN: STATUS BOARD <Run Foreground="#FFD1BA2B">BETA</Run>
                </TextBlock>
            </StackPanel>
            <ProgressBar Grid.Row="1" IsIndeterminate="True" IsEnabled="True" Visibility="{Binding Loading, Converter={StaticResource BooltoVisibility}}" Height="20" Foreground="{StaticResource PrimaryColourBrush}" />
            <TextBlock Grid.Row="1" FontSize="20" VerticalAlignment="Center">
                <Run xml:space="preserve">Project Status @ </Run><Run Text="{Binding LastUpdated, Converter={StaticResource DateTimePrettifier}}" />
            </TextBlock>

            <Grid Grid.Row="3" HorizontalAlignment="Stretch" Background="Transparent">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="4*" />
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Text="Title" Style="{StaticResource TitleTextBlockStyle}" />
                <TextBlock Grid.Column="1" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Text="Status" Style="{StaticResource TitleTextBlockStyle}" />
            </Grid>
            <ItemsControl Grid.Row="4" Grid.Column="1" Background="{x:Null}" Foreground="White" ItemsSource="{Binding DetailedItems}" ItemTemplate="{StaticResource DetailedItemDataTemplate}" />
        </Grid>

        <Popup IsOpen="{Binding ShowUpdating, Mode=TwoWay}">
            <Grid Width="{Binding ActualWidth, ElementName=page}" Height="{Binding ActualHeight, ElementName=page}" Background="#99000000">
                <Border BorderBrush="White" VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="2" Padding="12,12,12,12" Background="#141A24">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="updating... please wait..."  FontSize="24" FontWeight="Light" />
                        <ProgressBar Grid.Row="1" IsIndeterminate="True" />
                    </Grid>
                </Border>
            </Grid>
        </Popup>

        <Popup IsOpen="{Binding PasswordPrompt, Mode=TwoWay}">
            <Grid Width="{Binding ActualWidth, ElementName=page}" Height="{Binding ActualHeight, ElementName=page}" Background="#99000000">
                <Border BorderBrush="White" VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="2" Padding="12,12,12,12" Background="#141A24">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="please provide your password to continue"  FontSize="24" FontWeight="Light" />
                        <PasswordBox  Grid.Row="1" Password="{Binding UserProvidedPassword, Mode=TwoWay}" />
                        <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right">
                            <Button Content="settings" Command="{Binding GoToSettings}" />
                            <Button Content="okay"  Command="{Binding PasswordProvided}" />
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>
        </Popup>
    </Grid>
</Page>